package controllers

import (
	"errors"
	"share/base"
	"share/models"
	"fmt"
)

// Operations about Users
type ShopController struct {
	base.SuperController
}

// @添加商店分类
// @Description desc
// @Param	name		query 	string	true		"分类名称"
// @Param	parent_id	query 	int		false		"父分类Id"
// @Success 200 {object} models.ShopCate
// @router /cate/add [put]
func (c *ShopController) PutCate() {
	var shopCate models.ShopCate
	c.ParseForm(&shopCate)
	db := c.FYDB()

	_, err := db.InsertOne(&shopCate)
	c.ErrStop(err)

	c.Success(shopCate)

}

// @根据id获取分类
// @Description desc
// @Param	id		query 	int64	true		"分类id"
// @Success 200 {string} login success
// @router /cate/get
func (c *ShopController) Get() {
	cid, _ := c.GetInt64("id")
	db := c.FYDB()
	var shopCate models.ShopCate
	shopCate.Id = cid
	has, err := db.Get(&shopCate)
	c.ErrStop(err)
	if !has {
		c.ErrStop(errors.New("no result"))
	}
	c.Success(shopCate)
}

// @获取所有分类
// @Description desc
// @Success 200 {string} login success
// @router /cate/all
func (c *ShopController) AllCates() {
	db := c.FYDB()
	var shopCates []models.ShopCate
	err := db.Find(&shopCates)
	c.ErrStop(err)
	c.Success(shopCates)
}

// @添加商品
// @Description desc
// @Param	scenic_id		query 	int		false		"景点id"
// @Param	cate_id			query 	int		true		"分类id"
// @Param	name			query 	string	true		"商店名称"
// @Param	photo			query 	string	false		"商店主图"
// @Param	tel				query 	string	false		"联系座机"
// @Param	lon				query 	float64	false		"经度"
// @Param	lat				query 	float64	false		"纬度"
// @Param	province_code	query 	int		false		"省份编码"
// @Param	city_code		query 	int		false		"城市编码"
// @Param	district_code	query 	int		false		"地区编码"
// @Param	province_name	query 	string	false		"省份"
// @Param	city_name		query 	string	false		"城市"
// @Param	district_name	query 	string	false		"地区"
// @Param	address			query 	string	false		"地区"
// @Success 200 {object} models.shop
// @router /add [put]
func (c *ShopController) Put() {
	var shop models.Shop
	c.ParseForm(&shop)
	db := c.FYDB()

	fmt.Println(shop)
	_, err := db.Insert(&shop)
	c.ErrStop(err)

	c.Success(shop)

}

// @获取所有店家
// @Description desc
// @Success 200 {string} login success
// @router /all
func (c *ShopController) All() {
	db := c.FYDB()
	var shops []models.Shop
	err := db.Find(&shops)
	c.ErrStop(err)
	c.Success(shops)
}






